package com.yzion

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.LogUtils
import com.scwang.smartrefresh.header.MaterialHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.yzion.baseapp.R
import com.yzion.baselib.app.BaseApp
import com.yzion.baselib.widget.titlebar.DefaultTitleBar.Companion.setTitleBarDefaultAttr
import com.yzion.baselib.widget.titlebar.DefaultTitleBar.TitleBarDefaultAttr
import com.yzion.demo_refreshlayout.SuperTitleBar
import com.yzion.util.VPNController
import com.yzion.widgetlib.refreshrecyclerview.DefaultRefreshFooter
import me.yokeyword.fragmentation.Fragmentation

/**
 * ZJJ
 */
class App : BaseApp() {

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
    }

    override fun onCreate() {
        super.onCreate()

//        QbSdk.initX5Environment(getApplicationContext(), new QbSdk.PreInitCallback() {
//            @Override
//            public void onCoreInitFinished() {
//
//            }
//
//            @Override
//            public void onViewInitFinished(boolean b) {
//                LogUtils.d("x5內核初始化:" + b);
//            }
//        });
        VPNController.register(this)
        LogUtils.getConfig().setBorderSwitch(false)
        Fragmentation.builder() // 设置 栈视图 模式为 （默认）悬浮球模式   SHAKE: 摇一摇唤出  NONE：隐藏， 仅在Debug环境生效
            .stackViewMode(Fragmentation.BUBBLE)
            .debug(true) // 实际场景建议.debug(BuildConfig.DEBUG)
            /**
             * 可以获取到[me.yokeyword.fragmentation.exception.AfterSaveStateTransactionWarning]
             * 在遇到After onSaveInstanceState时，不会抛出异常，会回调到下面的ExceptionHandler
             */
            .handleException {
                // 以Bugtags为例子: 把捕获到的 Exception 传到 Bugtags 后台。
                // Bugtags.sendException(e);
            }
            .install()

        setTitleBarDefaultAttr(object : TitleBarDefaultAttr {
            override fun leftIcon(): Drawable? {
                return null
            }

            override fun rightIcon(): Drawable? {
                return null
            }

            override fun rightTextColor(): Int {
                return ColorUtils.getColor(R.color.color_white)
            }

            override fun leftTextColor(): Int {
                return ColorUtils.getColor(R.color.color_white)
            }

            override fun titleBarHeightDp(): Int {
                return 50
            }

            override fun rightTextSizeDp(): Int {
                return 14
            }

            override fun leftTextSizeDp(): Int {
                return 14
            }

            override fun titleTextSizeDp(): Int {
                return 18
            }

            override fun centerIcon(): Drawable? {
                return null
            }

            override fun background(): Drawable? {
                return null
            }

            override fun titleTextColor(): Int {
                return ColorUtils.getColor(R.color.white)
            }

            override fun backgroundColor(): Int {
                return ColorUtils.getColor(R.color.colorPrimary)
            }
        })

        // 统一配置刷新控件的header和footer的动画效果
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ ->
            MaterialHeader(context).apply {
                setColorSchemeColors(
                    ColorUtils.getColor(R.color.colorAccent),
                    ColorUtils.getColor(R.color.colorPrimary)
                )
            }
        }
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
            DefaultRefreshFooter.newInstance(context)
        }
    }

//    override fun <TitleBar : View> createTitleBarView(context: Context): TitleBar {
//        return SuperTitleBar(context) as TitleBar
//    }

}